<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/26
 * Time: 9:30
 */

namespace app\financial\controller;


use app\financial\model\DiscountModel;
use cmf\controller\AdminBaseController;

class DiscountController extends  AdminBaseController
{
    public function index()
    {

        $param=$this->request->param();
        $discount_model=new DiscountModel();
        $data=$discount_model->getList($param);
        $this->assign('data',$data);
        $this->assign('page',$data->render());

        $this->assign('param',$param);
        return $this->fetch();
    }
    public function addPost()
    {
        if($this->request->isPost())
        {

            $param=$this->request->param();
            $post=$this->request->post();

            $type=$post['type'];
            $start_time=$post['start_time'];
            $end_time=$post['end_time'];
            $reduce_price=$post['reduce_price'];
            $discount=$post['discount'];

            $type=$post['type'];

            if(empty($type))
            {
                $this->error('选择类型');
            }
            if(empty($type) || empty($type))
            {
                $this->error('选择输入时间');
            }
            if(empty($reduce_price) &&  empty($discount))
            {
                $this->error('选择输入折扣或者金额');
            }
            $discount_model=new DiscountModel();
            if($type==1)
            {
                $data=[];
                $data['type']=$post['type'];
                $data['total_price']=$post['total_price'];
                $data['reduce_price']=$post['reduce_price'];
                $data['start_time']=strtotime($post['start_time']);
                $data['end_time']=strtotime($post['end_time']);
                $data['create_time']=time();
                $insert_id=$discount_model->insertGetId($data);
                if($insert_id)
                {
                    $this->success('添加优惠活动成功');
                }

                $this->error('添加优惠活动失败');
            }
            if($type==2)
            {
                $data=[];
                $data['type']=$post['type'];
                $data['total_price']=$post['total_price'];
                $data['discount']=$post['discount'];
                $data['start_time']=strtotime($post['start_time']);
                $data['end_time']=strtotime($post['end_time']);
                $data['create_time']=time();
                $insert_id=$discount_model->insertGetId($data);
                if($insert_id)
                {
                    $this->success('添加优惠活动成功');
                }

                $this->error('添加优惠活动失败');

            }
        }

    }
    public function delete()
    {

    }
}